class indexlunBoth {
    constructor() {
        //@轮播图
        this.getDjinn();
        this.liBanging()
        this.youAnnie()
        this.zuoAnnie()
        this.ziDonged()
        this.zanTing()
        this.jiAuks()
        //@吸顶
        this.xiDing()
        //@倒计时
        this.Thecountdown()
        //@跑马灯
        this.paoMaled()

    };
    // > 轮播图
    getDjinn() {
        this.ul = document.querySelectorAll('#lbt li')
        this.ol = document.querySelectorAll('ol li');
        this.goPrev = document.getElementById('goPrev');
        this.goNext = document.getElementById('goNext');
    }

    lastIndex = 0;
    index = 0;
    liBanging() {
        //给ol 所有的li绑定事件
        this.ol.forEach((li, key) => {
            li.onclick = () => {
                this.lastIndex = this.index;
                //要出来的索引和实际索引相等
                this.index = key
                this.change() //调用change 使图片动起来
            }
        })
    }
    change() {
        this.ul[this.lastIndex].className = '';
        this.ol[this.lastIndex].className = '';
        this.ul[this.index].className = 'ac';
        this.ol[this.index].className = 'ac'

    };
    youAnnie() {
        this.goNext.onclick = () => {
            this.lastIndex = this.index;
            this.index++;
            if (this.index > this.ul.length - 1) {
                this.index = 0
            }
            this.change()
        }

    }
    zuoAnnie() {
        this.goPrev.onclick = () => {
            this.lastIndex = this.index;
            this.index--;
            if (this.index < 0) {
                this.index = this.ul.length - 1;
            }
            this.change()
        };
    };
    times = '';
    ziDonged() {
        this.times = setInterval(() => {
            this.goNext.onclick();
        }, 1500)
    }
    zanTing() {
        this.goNext.parentNode.onmouseover = () => {
            clearInterval(this.times)
        };
    };
    jiAuks() {
        this.goNext.parentNode.onmouseout = () => {
            this.ziDonged();
        }
    }
    // > 轮播完



    //>回到顶部
    xiDing() {
        $('.head').click(function () {
            // animate 动画
            $('html,body').animate({ scrollTop: 0 }, 500);
        })
    }

    //>倒计时
    Thecountdown() {
        //倒计时总秒数量
        let firstIntDiff = parseInt(86400);
        function timer(int, idN) {
            window.setInterval(function () {
                let day = 0,
                    hour = 0,
                    fen = 0,
                    miao = 0;
                if (int > 0) {
                    hour = Math.floor(int / (60 * 60)) - (day * 24);
                    fen = Math.floor(int / 60) - (day * 24 * 60) - (hour * 60);
                    miao = Math.floor(int) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (fen * 60);
                }
                if (miao <= 9) miao = '0' + miao;
                $(idN + ' .hour_show').html('<s id="h"></s>' + hour);
                $(idN + ' .minute_show').html('<s></s>' + fen);
                $(idN + ' .second_show').html('<s></s>' + miao);
                int--;
            }, 1000);
        }

        $(function () {
            timer(firstIntDiff, '#first');
        });
    }

    //>跑马灯
    paoMaled() {
        var marqueeBox = document.getElementById("marquee-box");
		var marquee = document.getElementById("marquee");
		var marqueeCopy = document.getElementById("marquee-1");

        // console.log(marqueeBox,marquee,marqueeCopy);
		marqueeCopy.innerHTML = marquee.innerHTML;
		function fun() {
			//从右向左
			if (marqueeBox.scrollLeft >= 800) {
				marqueeBox.scrollLeft = 0;
			} else {
				marqueeBox.scrollLeft++;
			}
		}

		let fun1 = setInterval(fun, 18);

		marqueeBox.onmouseover = function () {
			//鼠标经过时  清除定时器  停止图片的滚动
			clearInterval(fun1);
		};
		marqueeBox.onmouseout = function () {
			//鼠标离开后  继续滚动图片
			fun1 = setInterval(fun, 50);
		};

    }

}
new indexlunBoth();